# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=proj
pkgver=9.0.0
pkgrel=0
pkgdesc="PROJ coordinate transformation software library"
url="https://proj.org/"
arch="all"
license="MIT"
makedepends="cmake sqlite sqlite-dev gtest-dev tiff-dev
	curl-dev"
checkdepends="bash"
subpackages="
	$pkgname-doc
	$pkgname-util:util
	$pkgname-dev
	"
source="
	https://download.osgeo.org/proj/proj-$pkgver.tar.gz
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-DUSE_EXTERNAL_GTEST=ON \
		$CMAKE_CROSSOPTS .
	make
}

check() {
	case "$CARCH" in
		x86) sed -i "s/tolerance 3 mm/tolerance 10 mm/" test/gie/adams_ws2.gie && \
		     sed -i '2618s/tolerance 0.1 mm/tolerance 40 mm/' test/gie/builtins.gie && \
		     sed -i '2629s/tolerance 0.1 mm/tolerance 40 mm/' test/gie/builtins.gie && \
		     sed -i '2642s/tolerance 0.1 mm/tolerance 40 mm/' test/gie/builtins.gie && \
		     sed -i '2645s/tolerance 0.1 mm/tolerance 40 mm/' test/gie/builtins.gie;;
	esac
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest --force-new-ctest-process -E \
		'(nkg|testprojinfo|proj_test_cpp_api)'
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}

util() {
	pkgdesc="Cartographic projection library (utilities)"

	mkdir -p "$subpkgdir/usr"
	mv "$pkgdir/usr/bin" "$subpkgdir/usr"
}

sha512sums="
ae1e65f03fba1e922a61f843b64cf4fde0ff015ef8c18bde0a10cb3e732c4d1b27d2c6b0179e8456338c552a760de22abf16e887fc92118288ffa394a9c6a000  proj-9.0.0.tar.gz
"
